package cn.itcast.test;

import cn.itcast.utils.JdbcUtils;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class DruidTest01 {
    public static void main(String[] args) throws Exception {

        InputStream is = DruidTest01.class.getClassLoader().getResourceAsStream("druid.properties");

        Properties prop = new Properties();
        prop.load(is);

        DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);

        Connection con = dataSource.getConnection();

        //返回编译对象
        PreparedStatement ps = con.prepareStatement("SELECT * FROM student WHERE sid>?");
        //给问号赋值
        ps.setInt(1,0);
        //执行sql语句
        ResultSet rs = ps.executeQuery();
        //展示
        while (rs.next()) {
            Integer sid = rs.getInt("sid");
            String name = rs.getString("name");
            Integer age = rs.getInt("age");
            String birthday = rs.getString("birthday");
            System.out.println(sid+","+name+","+age+","+birthday);
        }

        JdbcUtils.close(con,null,rs);

    }
}
